﻿
using Patterns4Net.Core;

namespace Patterns4Net.Tests.PatternEnforcer.Core.Patterns.Regression
{
    using System;
    using NUnit.Framework;
    using Patterns4Net.Core.Patterns;
    using Patterns4Net.PatternEnforcer.Core.Patterns;

    [TestFixture]
    public class TemplateMethodCheckerTest : PatternCheckerTestBase
    {
        [Test]
        [TestCase("NotReallyATemplateMethod")]
        [TestCase("TemplateMethod")]
        public void RunAllTests(string method)
        {
            this.TestChecker(
                new TemplateMethodChecker(new PatternsLocator(new IPatternsProvider[0])), 
                typeof(TemplateMethodCheckerTest), 
                method,
                m => new TemplateMethod(m));
        }

        [PatternTest(false)]
        public void NotReallyATemplateMethod()
        {
            for (int i = 0; i < 5; i++)
            {
                this.NotAHook();
            }
        }

        [PatternTest(true)]
        public double TemplateMethod()
        {
            double result = 0;
            for (int i = 0; i < this.Hook1(); i++)
            {
                result = this.Hook2(result);
            }

            return result;
        }

        public virtual int Hook1()
        {
            return 0;
        }

        public virtual double Hook2(double x)
        {
            return Math.PI;
        }

        public int NotAHook()
        {
            return 42;
        }
    }
}
